package com.marcocirillo.justweet;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import twitter4j.TwitterException;

public class Controller implements ActionListener {

	//private JusTweet jt;
	private View v;
	
	public Controller(/*JusTweet jt, */View v)
	{
		//this.jt = jt;
		this.v = v;
	}
	@Override
	public void actionPerformed(ActionEvent e) {

		String s = e.getActionCommand();
		if (s.equals(View.TWEET_TEXT))
		{
			String username = v.getUsernameText();
			String password = v.getPasswordText();
			JusTweet jt = new JusTweet(username, password);
			
			try 
			{
				jt.updateStatus(v.getTweetText());
			} catch (TwitterException e1) 
			{
				System.out.println(e1.getMessage());
			}
		
			v.clearTweetText();
			try {
				v.setCurrentStatus(jt);
			} catch (TwitterException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
		}

	}

}
